package com.qdu.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qdu.entity.Student;
import com.qdu.service.StudentService;

@RestController
public class InfoController {
	@Autowired
	StudentService studentService;
	//经验证后，用户信息在会话范围存储，可通过给方法添加Authentication类型的参数获取已验证的用户的信息
	@GetMapping("/checkAuth")
	public Map<String,Object> getAuthenticatedUserInfo(Authentication auth,HttpSession session) {
		Student stu = studentService.selectStudentById("2018204550");
		session.setAttribute("loginStudent", stu);
		session.setAttribute("currentTermId", 1);
		System.out.println("1");
		Map<String,Object> infoMap=new HashMap<>();
		infoMap.put("userid", auth.getName());
		infoMap.put("roles", new ArrayList<>(auth.getAuthorities()));
		infoMap.put("isAuthenticated",auth.isAuthenticated());
		return infoMap;
	}
	
}
